#pragma once    
#include<iostream>
#include<unistd.h>
#include<pthread.h>
#include<vector>
#include<string>


namespace MutexModule
{
    class Mutex
    {
    public:
        Mutex()
        {
            pthread_mutex_init(&_mutex,nullptr);
        }

        void Lock()
        {
            pthread_mutex_lock(&_mutex); //对相应的变量进行上锁处理
        }

        void Unlock()
        {
            pthread_mutex_unlock(&_mutex);
        }

        pthread_mutex_t* GetMutex()
        {
            return &_mutex;
        }

        ~Mutex()
        {
            pthread_mutex_destroy(&_mutex);
        }
    private:
        pthread_mutex_t _mutex; //代表着锁的变量
    };
    //上面是描述锁，下面是为了让锁更好的工作，所以要进行锁的包装


    class LockGurd
    {
    public:
        LockGurd(Mutex &mutex) : _mutex(mutex)
        {
            _mutex.Lock();
        }
        ~LockGurd()
        {
            _mutex.Unlock();
        }
    private:
        Mutex &_mutex;
    };
}